home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************
- *** WheelChairSprite.c
- *** By: Stefan C. Sinclair
- *** Copyright © 1996 All Rights Reserved Worldwide.
- *** Brief description here
- *******************************************************/
-
- #include "SpriteForeground.h"
-
- // Wheel chair dude starts on left side of screen & comes right
-
- extern CWindowPtr gWindowP;
- extern short gFrameAdvanceTime;
- extern RgnHandle gWorkRgn;
-
- void SetupWheelChairSprite(SpritePtr spriteP)
- {
- Rect tempBoundsRect, moveBoundsRect;
- short horizMoveDelta;
- short vertMoveDelta;
-
- moveBoundsRect = gWindowP->portRect;
- moveBoundsRect.left -= 400;
- moveBoundsRect.right += 400;
-
- tempBoundsRect = moveBoundsRect;
- horizMoveDelta = 2; //GetRandom(2, 6);
- vertMoveDelta = 0; //GetRandom(2, 6);
-
- // calculate the movement boundary rectangle
- //InsetRect(&tempBoundsRect, horizMoveDelta, vertMoveDelta);
-
- // set the sprite’s movement characteristics
- SWSetSpriteMoveBounds(spriteP, &tempBoundsRect);
- SWSetSpriteMoveDelta(spriteP, horizMoveDelta, vertMoveDelta);
- SWSetSpriteMoveProc(spriteP, WheelChairMoveProc); //• mine
- // Slow down a bit...
- SWSetSpriteMoveTime(spriteP, 4*5*(20-gFrameAdvanceTime-1));
- SWSetSpriteFrameTime(spriteP, 4*5*(20-gFrameAdvanceTime-1));
- SWSetSpriteFrameRange(spriteP, 0, 1);
- SWSetSpriteFrameAdvance(spriteP, 1);
- // Default draw proc = CopyBits
- SWSetSpriteCollideProc(spriteP, WheelChairSpriteCollideProc); // mine
- // set the sprite’s initial location
- SWSetSpriteLocation(spriteP, -300, (moveBoundsRect.bottom - 100));
- }
-
- // WheelChairSpriteCollideProc----------------------------------------------------------------
- void WheelChairSpriteCollideProc(SpritePtr srcSpriteP,SpritePtr dstSpriteP,Rect* sectRect)
- {
- // uncomment for collision detection
- /*
- Rect rgnRect;
- //unsigned char *srcSpriteDataPtr,*dstSpriteDataPtr; // use as an array of 8 u. chars.
-
- // Access sprite's userData
- //srcSpriteDataPtr = (unsigned char *)&srcSpriteP->userData;
- //dstSpriteDataPtr = (unsigned char *)&dstSpriteP->userData;
-
- // If both sprites use the same collision routine (this one),ignore the second collision.
- if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
- ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
- (srcSpriteP > dstSpriteP)))
- return;
-
- rgnRect = (**srcSpriteP->curFrameP->maskRgn).rgnBBox;
-
- // move the mask region to the new sprite location
- OffsetRgn(srcSpriteP->curFrameP->maskRgn,
- (srcSpriteP->destFrameRect.left - rgnRect.left) +
- srcSpriteP->curFrameP->offsetPoint.h,
- (srcSpriteP->destFrameRect.top - rgnRect.top) +
- srcSpriteP->curFrameP->offsetPoint.v);
-
- rgnRect = (**dstSpriteP->curFrameP->maskRgn).rgnBBox;
-
- // move the mask region to the new sprite location
- OffsetRgn(dstSpriteP->curFrameP->maskRgn,
- (dstSpriteP->destFrameRect.left - rgnRect.left) +
- dstSpriteP->curFrameP->offsetPoint.h,
- (dstSpriteP->destFrameRect.top - rgnRect.top) +
- dstSpriteP->curFrameP->offsetPoint.v);
-
- SectRgn(srcSpriteP->curFrameP->maskRgn, dstSpriteP->curFrameP->maskRgn, gWorkRgn);
-
- if (!EmptyRgn(gWorkRgn)) // There is an overlap
- {
- return;
- }
- */
- return; // bare minimum!
- }
-
- /** WheelChairMoveProc **/
- // Here, reset sprite frame range as necessary depending on location.
- SW_FUNC void WheelChairMoveProc(SpritePtr srcSpriteP, Point* spritePoint)
- {
- unsigned char *spriteDataPtr; // use as an array of 8 u. chars.
- Rect viewRect = gWindowP->portRect;
-
- // Access sprite's userData
- //spriteDataPtr = (unsigned char *)&srcSpriteP->userData;
-
- // hit left boundary
- if (srcSpriteP->destFrameRect.left <= srcSpriteP->moveBoundsRect.left)
- {
- srcSpriteP->horizMoveDelta *= -1; // reverse drxn
- spritePoint->h = srcSpriteP->moveBoundsRect.left + 400;
- SWSetSpriteLocation(srcSpriteP, spritePoint->h, spritePoint->v);
- }
- // hit right boundary
- if (srcSpriteP->destFrameRect.right >= srcSpriteP->moveBoundsRect.right)
- {
- srcSpriteP->horizMoveDelta *= -1; // reverse drxn
- spritePoint->h = srcSpriteP->moveBoundsRect.right - 400;
- SWSetSpriteLocation(srcSpriteP, spritePoint->h, spritePoint->v);
-
- }
-
- // Adjust frame range
- if(srcSpriteP->horizMoveDelta > 0) // moving right
- SWSetSpriteFrameRange(srcSpriteP, 0, 1);
- else // moving left
- SWSetSpriteFrameRange(srcSpriteP, 2, 3);
- }